package com.ys.controller.api.kefu;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.kefu.TkfKnowOpinion;
import com.ys.service.kefu.TkfKnowOpinionService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/tkfKnowOpinion")
public class ApiInterTkfKnowOpinionController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<TkfKnowOpinion> commonApiService;
	@Autowired
	private TkfKnowOpinionService tkfKnowOpinionService;

	@RequiresPermissions("tkfKnowOpinion:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute TkfKnowOpinion cond
			){
		
		cond.addLeftJoin("TKF_Know B on B.Id = A.KnowId")
			.addField("B.Title knowTitle");
		
		return commonApiService.searchLay(cond);
	}
	
	@PostMapping("/add")
    @ResponseBody
	public R add(HttpServletRequest request,
			Long knowId,
			Integer score,
			String opinion
			){
		try {
			return tkfKnowOpinionService.add(knowId, opinion, score);
		} catch (Exception e) {
			e.printStackTrace();
			return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
		}
	}
}
